﻿using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace YJKRevitKernel.FormUtility.ModelessFormControlSuite
{
	public static class Utility
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		public static void SendEscToHandle(IWin32Window inputHandle)
		{
			int wMsg = 7;
			Utility.SendMessage(inputHandle.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
			int bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			Utility.keybd_event((byte)bVk, 0, dwFlags, 0);
			Utility.keybd_event((byte)bVk, 0, dwFlags2, 0);
		}
	}
}
